{% extends "forum/forumbase.html" %}

{% comment %}
#    Copyright 2012 New Mexico EPSCoR
#
#    This file is part of Teacher's P.E.T.
#
#    Teacher's P.E.T. is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Teacher's P.E.T. is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Teacher's P.E.T..  If not, see <http://www.gnu.org/licenses/>.
{% endcomment %}

{% load files %}

{% block title %} {{TheThread.title}} | {{TheForum.title}} | {{block.super}}{% endblock title %}

{% block css %}
    {{block.super}}
    <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/forum.css" >
{% endblock css %}

{% block content %}
<div class="forum-entries-index">
	<h2><a href="{% course_url forum_view_threads %}">{{TheThread.forum.title}}</a></h2>
	<div class="forum-entries-thread-title">
		<h1>{% if TheThread.is_sticky %}<span class="forum-entries-thread-title-sticky">[Sticky]</span>{% endif %}{{TheThread.title}}</h1>
		{% with CourseUser=users|getitem:request.user.username %}
		{% if CourseUser.status == "INSTRUCTOR" or CourseUser.status == "ASSISTANT" %}
			{% if TheThread.is_sticky %}<a class="forum-entries-button" href="{% course_url management app='forum' command='alter_thread' arguments=TheThread.id|concat:"&unsticky&view" %}" title="Unmark this thread as 'Sticky' - it will take its regular place in the thread listing">Unsticky</a>
			{% else %}<a class="forum-entries-button" href="{% course_url management app='forum' command='alter_thread' arguments=TheThread.id|concat:"&sticky&view" %}" title="Mark this thread as 'Sticky' - it will appear at the top of the thread listing">Sticky</a>
			{% endif %}
		
			{% if TheThread.is_locked %}<a class="forum-entries-button" href="{% course_url management app='forum' command='alter_thread' arguments=TheThread.id|concat:"&unlock&view" %}" title="Unlock this thread - new posts and post edits will be allowed">Unlock</a>
			{% else %}<a class="forum-entries-button" href="{% course_url management app='forum' command='alter_thread' arguments=TheThread.id|concat:"&lock&view" %}" title="Lock this thread - no new posts or post edits will be allowed">Lock</a>
			{% endif %}
		
			{% if TheThread.is_deleted %}<a class="forum-entries-button" href="{% course_url management app='forum' command='alter_thread' arguments=TheThread.id|concat:"&undelete&view" %}" title="Remove deletion mark - this thread will be viewable by everyone">Undelete</a>
			{% else %}<a class="forum-entries-button" href="{% course_url management app='forum' command='alter_thread' arguments=TheThread.id|concat:"&delete&view" %}" title="Mark this thread deleted - no one but Instructors and Assistants will be able to view this thread. Thread can be undeleted here or in Forum Management">Delete</a>
			{% endif %}
		{% endif %}
		{% endwith %}
	</div>
	<hr>
	<table class="forum-entries-header">
		<tr>
			<td class="forum-entries-create-new">
				{% if not TheThread.is_locked %}
				{% if not ban or ban.forum_ban < ban.BAN_POSTS %}
					<a class="forum-entries-button" href="{% course_url forum_create_entry thread_id=TheThread.id %}">Post Reply</a>
				{% endif %}
				{% else %}
					<img src="{{STATIC_URL}}images/locked.png" height="40" title="This thread is locked, no changes to it may be made">
				{% endif %}
			</td>
			<td class="forum-entries-navigation">
				Page {{page.number}} of {{page.paginator.num_pages}}
				{% if page.has_other_pages %}
					&nbsp;&nbsp;
					{% if page.has_previous %}<a href="{% course_url forum_view_entries_page thread_id=TheThread.id page='1' %}" title="Go to first page"><<</a>{% endif %}
					{% if page.number > 3 %}&nbsp;<a href="{% course_url forum_view_entries_page thread_id=TheThread.id page=page.number|add:"-3" %}">{{page.number|add:"-3"}}</a>{% endif %}
					{% if page.number > 2 %}&nbsp;<a href="{% course_url forum_view_entries_page thread_id=TheThread.id page=page.number|add:"-2" %}">{{page.number|add:"-2"}}</a>{% endif %}
					{% if page.number > 1 %}&nbsp;<a href="{% course_url forum_view_entries_page thread_id=TheThread.id page=page.number|add:"-1" %}">{{page.number|add:"-1"}}</a>{% endif %}
					&nbsp;{{page.number}}
					{% if page.pages_left >= 1 %}&nbsp;<a href="{% course_url forum_view_entries_page thread_id=TheThread.id page=page.number|add:"1" %}">{{page.number|add:"1"}}</a>{% endif %}
					{% if page.pages_left >= 2 %}&nbsp;<a href="{% course_url forum_view_entries_page thread_id=TheThread.id page=page.number|add:"2" %}">{{page.number|add:"2"}}</a>{% endif %}
					{% if page.pages_left >= 3 %}&nbsp;<a href="{% course_url forum_view_entries_page thread_id=TheThread.id page=page.number|add:"3" %}">{{page.number|add:"3"}}</a>{% endif %}
					{% if page.has_next %}&nbsp;<a href="{% course_url forum_view_entries_page thread_id=TheThread.id page=page.paginator.num_pages %}" title="Go to last page">>></a>{% endif %}
				{% endif %}
			</td>
		</tr>
	</table>
	<table class="forum-entries-table" cellpadding=0 cellspacing=0 border=0>
	{% for entry in page.object_list %}
		{% with hide_delete_attachment='True' %}
		{% get_file_list for entry as Files %}
		{% include "forum/forum/display_entry.html" %}
		{% endwith %}
	{% endfor %}
	</table>
	<table class="forum-entries-footer">
		<tr>
			<td class="forum-entries-create-new">
				{% if not TheThread.is_locked %}
				{% if not ban or ban.forum_ban < ban.BAN_POSTS %}
					<a class="forum-entries-button" href="{% course_url forum_create_entry thread_id=TheThread.id %}">Post Reply</a>
				{% endif %}
				{% endif %}
			</td>
			<td class="forum-entries-navigation">
				Page {{page.number}} of {{page.paginator.num_pages}}
				{% if page.has_other_pages %}
					&nbsp;&nbsp;
					{% if page.has_previous %}<a href="{% course_url forum_view_entries_page thread_id=TheThread.id page='1' %}" title="Go to first page"><<</a>{% endif %}
					{% if page.number > 3 %}&nbsp;<a href="{% course_url forum_view_entries_page thread_id=TheThread.id page=page.number|add:"-3" %}">{{page.number|add:"-3"}}</a>{% endif %}
					{% if page.number > 2 %}&nbsp;<a href="{% course_url forum_view_entries_page thread_id=TheThread.id page=page.number|add:"-2" %}">{{page.number|add:"-2"}}</a>{% endif %}
					{% if page.number > 1 %}&nbsp;<a href="{% course_url forum_view_entries_page thread_id=TheThread.id page=page.number|add:"-1" %}">{{page.number|add:"-1"}}</a>{% endif %}
					&nbsp;{{page.number}}
					{% if page.pages_left >= 1 %}&nbsp;<a href="{% course_url forum_view_entries_page thread_id=TheThread.id page=page.number|add:"1" %}">{{page.number|add:"1"}}</a>{% endif %}
					{% if page.pages_left >= 2 %}&nbsp;<a href="{% course_url forum_view_entries_page thread_id=TheThread.id page=page.number|add:"2" %}">{{page.number|add:"2"}}</a>{% endif %}
					{% if page.pages_left >= 3 %}&nbsp;<a href="{% course_url forum_view_entries_page thread_id=TheThread.id page=page.number|add:"3" %}">{{page.number|add:"3"}}</a>{% endif %}
					{% if page.has_next %}&nbsp;<a href="{% course_url forum_view_entries_page thread_id=TheThread.id page=page.paginator.num_pages %}" title="Go to last page">>></a>{% endif %}
				{% endif %}
			</td>
		</tr>
	</table>
</div>
{% endblock content %}